#include <stdio.h>

void menu()
{
    printf("-----------------------------\n");
    printf("---- 1. Add ---- 2. Sub -----\n");
    printf("---- 3. Mul ---- 4. Div -----\n");
    printf("---- 0. Exit ----------------\n");
    printf("-----------------------------\n");
}

int Add(int x, int y)
{
    return x+y;
}

int Sub(int x, int y)
{
    return x-y;
}

int Mul(int x, int y)
{
    return x*y;
}

int Div(int x, int y)
{
    return x/y;
}

int main()
{
    int input=0, x=0, y=0, ret=0;
    int (*pfArr[5])(int, int)={0, Add, Sub, Mul, Div};
    do
    {
        menu();
        printf("Please choose:>");
        scanf("%d",  &input);
        if (input==0) printf("Exit the calculator.\n");
        else if (input>=1 && input<=4)
        {
            printf("Please input two arguments:>");
            scanf("%d %d", &x,&y);
            ret=pfArr[input](x, y);
            printf("The result is %d.\n", ret);
        }
        else printf("Wrong choice.\n");
    }while (input);
    return 0;
}
